﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace eTerm.NetSocket
{
    public sealed class TravelSky2Socket:BaseTermSocket
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="eTerm443Socket"/> class.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="port">The port.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <param name="rid">The rid.</param>
        /// <param name="sid">The sid.</param>
        public TravelSky2Socket(string address, int port, string userName, string password)
            : base(address, port, true, userName, password, 0x00, 0x00, string.Empty)
        { 
            
        }

        /// <summary>
        /// Logs the in.
        /// </summary>
        protected override void LogIn()
        {
            //base.LogIn();
            SendStream(GetTravelSky2Creadit(UserName,Password));
        }

        /// <summary>
        /// Gets the travel sky2 creadit.
        /// </summary>
        /// <param name="UserName">Name of the user.</param>
        /// <param name="UserPWD">The user PWD.</param>
        /// <returns></returns>
        private byte[] GetTravelSky2Creadit(string UserName, string UserPWD)
        {
            int num;
            byte[] buffer = new byte[] { 
                1, 0xa2, 0x54, 0x57, 50, 0x31, 0x30, 50, 0x35, 0, 0x30, 50, 0x2e, 0x31, 0x30, 0x36, 
                0x2e, 0x31, 0x42, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
                0, 0
             };
            byte[] bytes = Encoding.ASCII.GetBytes(UserName);
            byte[] buffer3 = Encoding.ASCII.GetBytes(UserPWD);
            for (num = 2; num < (2 + bytes.Length); num++)
            {
                buffer[num] = bytes[num - 2];
            }
            for (num = 0x12; num < (0x12 + buffer3.Length); num++)
            {
                buffer[num] = buffer3[num - 0x12];
            }
            return buffer;
        }
    }
}
